﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using Pibby.Core.Opml;

namespace Pibby.Core
{
	public class PodcastCollectionExporter
	{
		public PodcastCollectionExporter()
		{
			this.Podcasts = new PodcastCollection();
		}

		public PodcastCollection Podcasts
		{
			get;
			set;
		}

		public void Save(TextWriter stream)
		{
			var document = new OpmlDocument();
	
			document.Title = "Podcasts exported from Pibby 1.0";
			document.ModifiedDate = DateTime.Now;
			document.Version = "1.0";

			foreach (var p in this.Podcasts)
			{
				document.Outlines.Add(new Outline()
				{
					HtmlUrl = p.Feed,
					XmlUrl = p.Feed,
					Text = p.Name,
					Title = p.Name,
					OutlineType = OutlineType.Rss
				});
			}

			stream.Write (document.ToString());
		}
	}
}
